/*
 * UserInfoPanel.java
 *
 * Created on __DATE__, __TIME__
 */

package Windows.UserInfoWindow;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

import DBUtil.UserInfo;
import Tools.JLabelStyle;
import Tools.Log;
import Windows.PicPanel;
import WindowsModule.Update;

/**
 * 
 * @author __USER__
 */
public class UserInfoPanel extends PicPanel {
	private static ImageIcon ii1;
	private static ImageIcon ii2;
	// End of variables declaration//GEN-END:variables
	public static void main(String[] args) {
		JFrame jf = new JFrame();
		jf.setSize(400, 300);
		jf.setContentPane(new UserInfoPanel());
		jf.setVisible(true);
	}
	private UserInfo ui;
	private PicPanel pn = new PicPanel("Skin/downExited.png", "Skin/downExited2.PNG");

	private Update infoWin;

	// GEN-BEGIN:variables
	// Variables declaration - do not modify
	public javax.swing.JPanel jPanel;

	private javax.swing.JLabel jlGrade;

	private javax.swing.JLabel jlICO;

	private javax.swing.JLabel jlInteger;
	private javax.swing.JLabel jlName;
	/** Creates new form UserInfoPanel */
	public UserInfoPanel() {
		super("Skin/Window.jpg");
		initComponents();

		ii1 = new ImageIcon("Skin/Face/0.png");
		ii2 = new ImageIcon("Skin/Face/0_.png");

		this.jlName.addMouseListener(JLabelStyle.getStyleListener());
		this.jlInteger.addMouseListener(JLabelStyle.getStyleListener());
		this.jlGrade.addMouseListener(JLabelStyle.getStyleListener());
		this.jlICO.addMouseListener(JLabelStyle.getStyleListener());

		MouseListener ml = new MouseListener() {

			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				Object obj = e.getSource();
				if (obj.getClass() == JLabel.class) {
					JLabel jl = (JLabel) obj;
					if (jl.equals(jlName)) {
						Log.print("[用户信息]用户名被单击！");
						getInfoWindow().initInfo(ui.getId(), true);

					} else if (jl.equals(jlInteger)) {
						Log.print("[用户信息]积分被单击！");
					} else if (jl.equals(jlGrade)) {
						Log.print("[用户信息]等级被单击！");
					} else if (jl.equals(jlICO)) {
						Log.print("[用户信息]等级被单击！");
					}
				}
			}

			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
				Object obj = e.getSource();
				if (obj.getClass() == JLabel.class) {
					JLabel jl = (JLabel) obj;
					if (jl.equals(jlICO)) {
						jlICO.setIcon(UserInfoPanel.ii2);

					}
				}
			}

			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				Object obj = e.getSource();
				if (obj.getClass() == JLabel.class) {
					JLabel jl = (JLabel) obj;
					if (jl.equals(jlICO)) {
						jlICO.setIcon(UserInfoPanel.ii1);

					}
				}
			}

			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				Object obj = e.getSource();
				if (obj.getClass() == JLabel.class) {
					JLabel jl = (JLabel) obj;
					if (jl.equals(jlICO)) {
						jlICO.setIcon(UserInfoPanel.ii1);
					}
				}
			}

			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				Object obj = e.getSource();
				if (obj.getClass() == JLabel.class) {
					JLabel jl = (JLabel) obj;
					if (jl.equals(jlICO)) {
						jlICO.setIcon(UserInfoPanel.ii2);
					}
				}
			}

		};
		this.jlName.addMouseListener(ml);
		this.jlInteger.addMouseListener(ml);
		this.jlGrade.addMouseListener(ml);
		this.jlICO.addMouseListener(ml);

		ImageIcon ii = new ImageIcon("Skin/downfile.png");
		this.jlICO.setIcon(ii);
		jlICO.setSize(ii.getIconWidth(), ii.getIconHeight());

	}
	public Update getInfoWindow() {
		if (infoWin == null) {
			infoWin = new Update();
		}
		return infoWin;
	}
	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jlICO = new javax.swing.JLabel();
		jlName = new javax.swing.JLabel();
		jlInteger = new javax.swing.JLabel();
		jPanel = this.pn;
		jlGrade = new javax.swing.JLabel();

		jlName.setText("UserName");
		jlName.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

		jlInteger.setText("\u79ef\u5206:1024");
		jlInteger.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

		jPanel.setBackground(new java.awt.Color(255, 255, 255));

		javax.swing.GroupLayout jPanelLayout = new javax.swing.GroupLayout(jPanel);
		jPanel.setLayout(jPanelLayout);
		jPanelLayout.setHorizontalGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 209, Short.MAX_VALUE));
		jPanelLayout.setVerticalGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 94, Short.MAX_VALUE));

		jlGrade.setText("\u7b49\u7ea7:1024");
		jlGrade.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
												.addGroup(layout.createSequentialGroup().addComponent(jlICO, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jlInteger, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE).addComponent(jlName, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE).addComponent(jlGrade, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)))).addContainerGap()));
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(jlName, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jlInteger).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jlGrade)).addComponent(jlICO, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap()));
	}// </editor-fold>
		// GEN-END:initComponents

	public void setUser(UserInfo ui) {
		if (ui == null) {
			ui = new UserInfo("匿名用户", 0, 0,0);
		}
		int i = ui.getGrade();
		this.ui = ui;
		this.jlName.setText(ui.getId());
		this.jlInteger.setText("积分: " + ui.getInteger());
		this.jlGrade.setText("等级: " + i+"("+ui.getOnlineTimeStr()+")");

		ImageIcon ii1 = new ImageIcon("Skin/Face/" + i + ".png");
		ImageIcon ii2 = new ImageIcon("Skin/Face/" + i + "_.png");

		UserInfoPanel.ii1 = ii1 == null ? UserInfoPanel.ii1 : ii1;
		UserInfoPanel.ii2 = ii2 == null ? UserInfoPanel.ii2 : ii2;

	}
}